#!/usr/bin/env ruby

# == Synopsis
# 
# Chemical class to access data
# == Copyright
# Copyright (c) 2008 Carsten Niehaus <cniehaus at kde dot org>
# Licence GPLv3

#This is just a shortcut
class ChemicalValue < Struct.new(:value, :unit); end

# This class represents a chemical element
class ChemicalElement
	attr_accessor :name, :number, :mass, :symbol, :exactMass, :ionization
	attr_accessor :electronegativityPauling, :electronicConfiguration, :electronAffinity
	attr_accessor :radiusVDW, :radiusCovalent, :boilingpoint, :meltingpoint

	def initialize
		@name  = ChemicalValue.new
		@number = ChemicalValue.new
		@mass  = ChemicalValue.new
		@symbol = ChemicalValue.new
		@exactMass  = ChemicalValue.new
		@ionization = ChemicalValue.new
		@electronegativityPauling = ChemicalValue.new
		@electronicConfiguration  = ChemicalValue.new
		@electronAffinity = ChemicalValue.new
		@radiusVDW  = ChemicalValue.new
		@radiusCovalent  = ChemicalValue.new
		@boilingpoint  = ChemicalValue.new
		@meltingpoint = ChemicalValue.new
	end
	
	#return the value of the queried property
	def value( property )
		if property == "EA"
			@electronAffinity[:value]
		elsif property == "EN"
			@electronegativityPauling[:value]
		end
	end

	#return the unit of the queried property
	def unit( property )
		if property == "EA"
			@electronAffinity[:unit]
		elsif property == "EN"
			@electronegativityPauling[:unit]
		end
	end

	# This methods returns all known data of a the element.
	# Helpful to debug the parser
	def debug
		puts "\n"
		puts "Name: #{@name[:value]} (#{@symbol[:value]}), Number: #{@number[:value]}".center( 72 )
		puts "Mass: #{@mass[:value]} (#{@mass[:unit]})"
		puts "EN (Pauling): #{@electronegativityPauling[:value]} (#{@electronegativityPauling[:unit]})"
		puts "exact mass: #{@exactMass[:value]} (#{@exactMass[:unit]})"
		puts "First Ionization Energy: #{@ionization[:value]}"
		puts "Electronic Configuration: #{@electronicConfiguration[:value]}"
		puts "Electronic Affinity: #{@electronAffinity[:value]}"
		puts "Radius (Covalent): #{@radiusCovalent[:value]}"
		puts "Radius (van der Waals): #{@radiusVDW[:value]}"
		puts "Boilingpoint: #{@boilingpoint[:value]}"
		puts "Meltingpoint: #{@meltingpoint[:value]}"
	end
end
